package com.example.plus5;

import java.io.Serializable;
import java.sql.Date;

import org.json.JSONException;
import org.json.JSONObject;

import android.location.Location;
import android.text.format.Time;


public class appointment implements Serializable, Comparable  {

	private String day;
	private String name;
	private String location;
	private String time;
	private String enable;
	
	
	

	public appointment(String name, String location, String day, String time){
		this.name = name;
		this.day = day;
		this.time = time;
		this.location = location;
		this.enable = "1";
		
	}
	
	public String getName() {
		return name;
	}
	public String getDay() {
		return day;
	}
	public String getTime() {
		return time;
	}
	public String getLocation() {
		return location;
	}

	public JSONObject getjSonObject(){
		JSONObject obj = new JSONObject();
	    try {
	        obj.put("name", this.name);
	        obj.put("day", this.day);
	        obj.put("time", this.time);
	        obj.put("location", this.location);
	        obj.put("enable", this.enable);
	    } catch (JSONException e) {
	        e.printStackTrace();
	    }
	    return obj;
	}
		
	

	private int value(String day) {
		if (day.equalsIgnoreCase("Monday"))
			return 7;
		else if (day.equalsIgnoreCase("Tuesday"))
			return 6;
		else if (day.equalsIgnoreCase("Wednesday"))
			return 5;
		else if (day.equalsIgnoreCase("Thursday"))
			return 4;
		else if (day.equalsIgnoreCase("Friday"))
			return 3;
		else if (day.equalsIgnoreCase("Saturday"))
			return 2;
		else if (day.equalsIgnoreCase("Sunday"))
			return 1;
		else 
			return -1;
		
	}


	@Override
	public int compareTo(Object arg0) {
		appointment toCompare = (appointment) (arg0);
		
		if (value(this.day) > (value(toCompare.day))) 
			return 1;
		else if (value(this.day) < (value(toCompare.day)))
			return -1;
		else {
			return (this.time.compareTo(toCompare.time));
		}
	}


}
